package com.hisky.cms.article.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.hisky.cms.article.service.ArticleService;
import com.hisky.cms.article.vo.Article;
import com.hisky.cms.menu.service.MenuService;
import com.hisky.cms.menu.vo.Menu;

@Controller
@RequestMapping("article")
public class ArticleController {
	@Autowired
	MenuService menuService;
	@Autowired
	ArticleService articleService;

	@RequestMapping(value = "add", method = { RequestMethod.GET })
	public ModelAndView add() {
		ModelAndView mav = new ModelAndView("article/add");
		Menu temp = new Menu();
		temp.setParrentId(0);
		List<Menu> menus = menuService.getList(temp);
		mav.addObject("menus", menus);
		return mav;
	}

	@RequestMapping(value = "add", method = { RequestMethod.POST })
	@ResponseBody
	public int add(Article article) {
		try {
			return articleService.add(article);
		} catch (Exception e) {
			e.printStackTrace();
			return 0;
		}
	}
}
